"use server"
import { signIn } from '@/lib/auth'

import { loginFormSchemaType } from './page'
import { AuthError } from 'next-auth'


export const loginWithGithub = async () => {
  await signIn('github')
}


export const loginWithGitee = async () => {
  await signIn('gitee')
}


export const loginWithEmail = async (credentials: loginFormSchemaType): Promise<void | { error?: string }> => {
  try {
    await signIn('credentials', {
      ...credentials,
    })
  } catch (error) {
    if (error instanceof AuthError) {
      return {
        error: '用户密码错误'
      }
    }

    // 必须抛出错误
    throw error
  }
}
